using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace SubSonic.Generated
{
	/// <summary>
	/// Strongly-typed collection for the Metadatum class.
	/// </summary>
    [Serializable]
	public partial class MetadatumCollection : ActiveList<Metadatum, MetadatumCollection>
	{	   
		public MetadatumCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>MetadatumCollection</returns>
		public MetadatumCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Metadatum o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the metadata table.
	/// </summary>
	[Serializable]
	public partial class Metadatum : ActiveRecord<Metadatum>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Metadatum()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Metadatum(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Metadatum(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Metadatum(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("metadata", TableType.Table, DataService.GetInstance("sqlite"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"main";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "id";
				colvarId.DataType = DbType.Int64;
				colvarId.MaxLength = 8;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarAlbum = new TableSchema.TableColumn(schema);
				colvarAlbum.ColumnName = "album";
				colvarAlbum.DataType = DbType.String;
				colvarAlbum.MaxLength = 2147483647;
				colvarAlbum.AutoIncrement = false;
				colvarAlbum.IsNullable = true;
				colvarAlbum.IsPrimaryKey = false;
				colvarAlbum.IsForeignKey = false;
				colvarAlbum.IsReadOnly = false;
				colvarAlbum.DefaultSetting = @"";
				colvarAlbum.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAlbum);
				
				TableSchema.TableColumn colvarArtist = new TableSchema.TableColumn(schema);
				colvarArtist.ColumnName = "artist";
				colvarArtist.DataType = DbType.String;
				colvarArtist.MaxLength = 2147483647;
				colvarArtist.AutoIncrement = false;
				colvarArtist.IsNullable = true;
				colvarArtist.IsPrimaryKey = false;
				colvarArtist.IsForeignKey = false;
				colvarArtist.IsReadOnly = false;
				colvarArtist.DefaultSetting = @"";
				colvarArtist.ForeignKeyTableName = "";
				schema.Columns.Add(colvarArtist);
				
				TableSchema.TableColumn colvarComposer = new TableSchema.TableColumn(schema);
				colvarComposer.ColumnName = "composer";
				colvarComposer.DataType = DbType.String;
				colvarComposer.MaxLength = 2147483647;
				colvarComposer.AutoIncrement = false;
				colvarComposer.IsNullable = true;
				colvarComposer.IsPrimaryKey = false;
				colvarComposer.IsForeignKey = false;
				colvarComposer.IsReadOnly = false;
				colvarComposer.DefaultSetting = @"";
				colvarComposer.ForeignKeyTableName = "";
				schema.Columns.Add(colvarComposer);
				
				TableSchema.TableColumn colvarGenre = new TableSchema.TableColumn(schema);
				colvarGenre.ColumnName = "genre";
				colvarGenre.DataType = DbType.String;
				colvarGenre.MaxLength = 2147483647;
				colvarGenre.AutoIncrement = false;
				colvarGenre.IsNullable = true;
				colvarGenre.IsPrimaryKey = false;
				colvarGenre.IsForeignKey = false;
				colvarGenre.IsReadOnly = false;
				colvarGenre.DefaultSetting = @"";
				colvarGenre.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGenre);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 2147483647;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				colvarTitle.DefaultSetting = @"";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarYear = new TableSchema.TableColumn(schema);
				colvarYear.ColumnName = "year";
				colvarYear.DataType = DbType.Int64;
				colvarYear.MaxLength = 8;
				colvarYear.AutoIncrement = false;
				colvarYear.IsNullable = true;
				colvarYear.IsPrimaryKey = false;
				colvarYear.IsForeignKey = false;
				colvarYear.IsReadOnly = false;
				colvarYear.DefaultSetting = @"";
				colvarYear.ForeignKeyTableName = "";
				schema.Columns.Add(colvarYear);
				
				TableSchema.TableColumn colvarTrack = new TableSchema.TableColumn(schema);
				colvarTrack.ColumnName = "track";
				colvarTrack.DataType = DbType.Int64;
				colvarTrack.MaxLength = 8;
				colvarTrack.AutoIncrement = false;
				colvarTrack.IsNullable = true;
				colvarTrack.IsPrimaryKey = false;
				colvarTrack.IsForeignKey = false;
				colvarTrack.IsReadOnly = false;
				colvarTrack.DefaultSetting = @"";
				colvarTrack.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTrack);
				
				TableSchema.TableColumn colvarDuration = new TableSchema.TableColumn(schema);
				colvarDuration.ColumnName = "duration";
				colvarDuration.DataType = DbType.String;
				colvarDuration.MaxLength = 2147483647;
				colvarDuration.AutoIncrement = false;
				colvarDuration.IsNullable = true;
				colvarDuration.IsPrimaryKey = false;
				colvarDuration.IsForeignKey = false;
				colvarDuration.IsReadOnly = false;
				colvarDuration.DefaultSetting = @"";
				colvarDuration.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDuration);
				
				TableSchema.TableColumn colvarBitrate = new TableSchema.TableColumn(schema);
				colvarBitrate.ColumnName = "bitrate";
				colvarBitrate.DataType = DbType.Int64;
				colvarBitrate.MaxLength = 8;
				colvarBitrate.AutoIncrement = false;
				colvarBitrate.IsNullable = true;
				colvarBitrate.IsPrimaryKey = false;
				colvarBitrate.IsForeignKey = false;
				colvarBitrate.IsReadOnly = false;
				colvarBitrate.DefaultSetting = @"";
				colvarBitrate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBitrate);
				
				TableSchema.TableColumn colvarBytesize = new TableSchema.TableColumn(schema);
				colvarBytesize.ColumnName = "bytesize";
				colvarBytesize.DataType = DbType.String;
				colvarBytesize.MaxLength = 2147483647;
				colvarBytesize.AutoIncrement = false;
				colvarBytesize.IsNullable = true;
				colvarBytesize.IsPrimaryKey = false;
				colvarBytesize.IsForeignKey = false;
				colvarBytesize.IsReadOnly = false;
				colvarBytesize.DefaultSetting = @"";
				colvarBytesize.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBytesize);
				
				TableSchema.TableColumn colvarHeight = new TableSchema.TableColumn(schema);
				colvarHeight.ColumnName = "height";
				colvarHeight.DataType = DbType.Int64;
				colvarHeight.MaxLength = 8;
				colvarHeight.AutoIncrement = false;
				colvarHeight.IsNullable = true;
				colvarHeight.IsPrimaryKey = false;
				colvarHeight.IsForeignKey = false;
				colvarHeight.IsReadOnly = false;
				colvarHeight.DefaultSetting = @"";
				colvarHeight.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHeight);
				
				TableSchema.TableColumn colvarWidth = new TableSchema.TableColumn(schema);
				colvarWidth.ColumnName = "width";
				colvarWidth.DataType = DbType.Int64;
				colvarWidth.MaxLength = 8;
				colvarWidth.AutoIncrement = false;
				colvarWidth.IsNullable = true;
				colvarWidth.IsPrimaryKey = false;
				colvarWidth.IsForeignKey = false;
				colvarWidth.IsReadOnly = false;
				colvarWidth.DefaultSetting = @"";
				colvarWidth.ForeignKeyTableName = "";
				schema.Columns.Add(colvarWidth);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sqlite"].AddSchema("metadata",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public long Id 
		{
			get { return GetColumnValue<long>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("Album")]
		[Bindable(true)]
		public string Album 
		{
			get { return GetColumnValue<string>(Columns.Album); }
			set { SetColumnValue(Columns.Album, value); }
		}
		  
		[XmlAttribute("Artist")]
		[Bindable(true)]
		public string Artist 
		{
			get { return GetColumnValue<string>(Columns.Artist); }
			set { SetColumnValue(Columns.Artist, value); }
		}
		  
		[XmlAttribute("Composer")]
		[Bindable(true)]
		public string Composer 
		{
			get { return GetColumnValue<string>(Columns.Composer); }
			set { SetColumnValue(Columns.Composer, value); }
		}
		  
		[XmlAttribute("Genre")]
		[Bindable(true)]
		public string Genre 
		{
			get { return GetColumnValue<string>(Columns.Genre); }
			set { SetColumnValue(Columns.Genre, value); }
		}
		  
		[XmlAttribute("Title")]
		[Bindable(true)]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }
			set { SetColumnValue(Columns.Title, value); }
		}
		  
		[XmlAttribute("Year")]
		[Bindable(true)]
		public long? Year 
		{
			get { return GetColumnValue<long?>(Columns.Year); }
			set { SetColumnValue(Columns.Year, value); }
		}
		  
		[XmlAttribute("Track")]
		[Bindable(true)]
		public long? Track 
		{
			get { return GetColumnValue<long?>(Columns.Track); }
			set { SetColumnValue(Columns.Track, value); }
		}
		  
		[XmlAttribute("Duration")]
		[Bindable(true)]
		public string Duration 
		{
			get { return GetColumnValue<string>(Columns.Duration); }
			set { SetColumnValue(Columns.Duration, value); }
		}
		  
		[XmlAttribute("Bitrate")]
		[Bindable(true)]
		public long? Bitrate 
		{
			get { return GetColumnValue<long?>(Columns.Bitrate); }
			set { SetColumnValue(Columns.Bitrate, value); }
		}
		  
		[XmlAttribute("Bytesize")]
		[Bindable(true)]
		public string Bytesize 
		{
			get { return GetColumnValue<string>(Columns.Bytesize); }
			set { SetColumnValue(Columns.Bytesize, value); }
		}
		  
		[XmlAttribute("Height")]
		[Bindable(true)]
		public long? Height 
		{
			get { return GetColumnValue<long?>(Columns.Height); }
			set { SetColumnValue(Columns.Height, value); }
		}
		  
		[XmlAttribute("Width")]
		[Bindable(true)]
		public long? Width 
		{
			get { return GetColumnValue<long?>(Columns.Width); }
			set { SetColumnValue(Columns.Width, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varAlbum,string varArtist,string varComposer,string varGenre,string varTitle,long? varYear,long? varTrack,string varDuration,long? varBitrate,string varBytesize,long? varHeight,long? varWidth)
		{
			Metadatum item = new Metadatum();
			
			item.Album = varAlbum;
			
			item.Artist = varArtist;
			
			item.Composer = varComposer;
			
			item.Genre = varGenre;
			
			item.Title = varTitle;
			
			item.Year = varYear;
			
			item.Track = varTrack;
			
			item.Duration = varDuration;
			
			item.Bitrate = varBitrate;
			
			item.Bytesize = varBytesize;
			
			item.Height = varHeight;
			
			item.Width = varWidth;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(long varId,string varAlbum,string varArtist,string varComposer,string varGenre,string varTitle,long? varYear,long? varTrack,string varDuration,long? varBitrate,string varBytesize,long? varHeight,long? varWidth)
		{
			Metadatum item = new Metadatum();
			
				item.Id = varId;
			
				item.Album = varAlbum;
			
				item.Artist = varArtist;
			
				item.Composer = varComposer;
			
				item.Genre = varGenre;
			
				item.Title = varTitle;
			
				item.Year = varYear;
			
				item.Track = varTrack;
			
				item.Duration = varDuration;
			
				item.Bitrate = varBitrate;
			
				item.Bytesize = varBytesize;
			
				item.Height = varHeight;
			
				item.Width = varWidth;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn AlbumColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn ArtistColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn ComposerColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn GenreColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn YearColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn TrackColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn DurationColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn BitrateColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn BytesizeColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn HeightColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        public static TableSchema.TableColumn WidthColumn
        {
            get { return Schema.Columns[12]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"id";
			 public static string Album = @"album";
			 public static string Artist = @"artist";
			 public static string Composer = @"composer";
			 public static string Genre = @"genre";
			 public static string Title = @"title";
			 public static string Year = @"year";
			 public static string Track = @"track";
			 public static string Duration = @"duration";
			 public static string Bitrate = @"bitrate";
			 public static string Bytesize = @"bytesize";
			 public static string Height = @"height";
			 public static string Width = @"width";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
